package com.springboot.demo.threadpool;

import org.apache.catalina.LifecycleState;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.RecursiveTask;
import java.util.stream.Collectors;

public class StringForkTest extends RecursiveTask<String> {
    String fork;

    StringForkTest(String f) {
        this.fork = f;
    }

    public String upString() {

        if (fork.length() % 2 == 0) {
            Integer a = fork.length() / 2;
            String start = fork.substring(0, a);
            String end = fork.substring(a);
            StringForkTest first = new StringForkTest(start);
            StringForkTest second = new StringForkTest(end);
            String c = first.fork().join();
            String b = second.fork().join();
            return c + b;
        } else {
            String upperCase = fork.toUpperCase();
            System.out.println(upperCase);
            return upperCase;
        }
    }

    @Override
    protected String compute() {
        return upString();
    }
}
